package com.jackrain.nea.fc.sc.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OmsScStockMapper {

    //查询所有的电商仓库存数据
    @SelectProvider(type = ViewScStockSql.class, method = "selectScStock")
    List<HashMap> selectScStock(@Param("storeid") Object[] storeid);

    //查询一定时间内变动过的 电商仓库存数据
    @SelectProvider(type = ViewScStockSql.class, method = "selectScStockChange")
    List<HashMap> selectScStockChange(@Param("storeid") Object[] storeid, @Param("now") String now, @Param("start") String start);

    class ViewScStockSql {
        public String selectScStock(Map<String, Object> map) {
            Object[] storeid = (Object[]) map.get("storeid");
            return new SQL() {
                {
                    SELECT("CP_C_STORE_ECODE AS CP_C_STORE_ECODE, " +
                            "QTY_STOCK_ABLE AS QTY_STOCK_ABLE, " +
                            "PS_C_SKU_ECODE AS PS_C_SKU_ECODE, " +
                            "MODIFIEDDATE AS MODIFIEDDATE " );
                    FROM("SC_B_STOCK");
                    StringBuffer sb = new StringBuffer();

                    for (int i = 0; i < storeid.length; i++) {
                        sb.append(storeid[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("CP_C_STORE_ID IN (" + sb.toString() + ")");
                    WHERE(" ISACTIVE = 'Y'");

                }
            }.toString();
        }
        public String selectScStockChange(Map<String, Object> map) {
            Object[] storeid = (Object[]) map.get("storeid");
            String now = map.get("now").toString();
            String start = map.get("start").toString();
            return new SQL() {
                {
                    SELECT("CP_C_STORE_ECODE AS CP_C_STORE_ECODE, " +
                            "QTY_STOCK_ABLE AS QTY_STOCK_ABLE, " +
                            "PS_C_SKU_ECODE AS PS_C_SKU_ECODE, " +
                            "MODIFIEDDATE AS MODIFIEDDATE " );
                    FROM("SC_B_STOCK");
                    StringBuffer sb = new StringBuffer();

                    for (int i = 0; i < storeid.length; i++) {
                        sb.append(storeid[i] + ",");
                    }
                    sb.deleteCharAt(sb.length() - 1);
                    WHERE("CP_C_STORE_ID IN (" + sb.toString() + ")");
                    WHERE("MODIFIEDDATE BETWEEN "+"'" + start + "'" + "AND" +"'"+now+"'");
                }
            }.toString();
        }
    }


}
